/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package crawler;

import com.util.DateUtil;
import com.util.HttpUtil;
import com.util.StringUtil;
import java.util.Vector;

/**
 *
 * @author SDS
 */
public class PassionScout {

    public String URL = "http://www.fashionscout.co.kr";

    public String URL_ALL       = URL + "/jobs/all/Default.asp?Temp=1";
    public String URL_DESIGN    = URL + "/jobs/part/joblist.asp?TopJc=1";
    public String URL_MARKETING = URL + "/jobs/part/joblist.asp?TopJc=7";
    public String URL_WEAR      = URL + "/jobs/industry/joblist.asp?TopComJc=1";

    public String REG_PATTERN_01 = "class\\s*=.*?cont0[1|2]";

    private String today = "";

    public PassionScout() {

        today = DateUtil.getToday( "MM/dd" );

    }

    /**
     * 패션스카우트 홈페이지에서 목록 데이터를 가져온다.
     * @param URL 목록정보를 가져올 URL 주소
     * @param page 페이지
     * @return 목록데이터 ( rows : ArrayList, cols : String )
     */
    public Vector<String[]> getData( String URL, int page ) {

        String pageText = HttpUtil.getPageContents( URL + "&page=" + page, "EUC-KR" );

        if( StringUtil.isEmpty(pageText) ) return new Vector<String[]>();

        String baseUrl  = URL.substring( 0, URL.lastIndexOf("/") );

        Vector<String[]> rows = HttpUtil.getTr( pageText, REG_PATTERN_01 );
        String[] cols;

        for( int inx = 0, inxCnt = rows.size(); inx < inxCnt; inx++ ) {

            cols = new String[ 8 ];

            System.arraycopy( rows.get(inx), 0, cols, 0, 7 );

            if( cols[0].indexOf("icon_today_new.gif") > 0 ) {
                cols[0] = this.today;
            }

            cols[1] = cols[1].replaceAll("<.*?>", "");

            String href  = baseUrl + "/" + HttpUtil.getAttrValue( "href", cols[3] );
            String title = HttpUtil.getAttrValue( "title", cols[3] );

            if( "".equals(title) ) title = HttpUtil.getInnerHTML( cols[3] );

            cols[3] = title;
            cols[7] = href;

            rows.set( inx, cols );

        }

        return rows;
    }

}
